#pragma once

// basic file operations
#include <iostream>
#include <fstream>
#include <list>

using namespace std;

class cachecontroler
{
public:
	cachecontroler(std::string url);
    cachecontroler(std::string url, bool write);
	~cachecontroler(void);

    void openFileWrite(std::string filename){
        ocachefile.open(filename.c_str());
	}

    void openFileRead(std::string filename) {
        icachefile.open(filename.c_str());
    }

	void closeFile() {
        if( ocachefile.is_open() ){
            ocachefile.flush();
            ocachefile.close();
        }

        if( icachefile.is_open() )
            icachefile.close();
	}

	void writeToFile(std::string data);

//    ifstream getFileRead() {
//        return icachefile;
//    }

    //==========list lock function==========
    static void insertLockList(std::string filename);
    static void removeLockList(std::string filename);
    static bool findLockList(std::string filename);

    static void printLockList();
    static std::list<std::string> lockFileList;

    //=========for hash url=================
    static std::string hashURLUtilities(std::string url);
    static std::string hashFilePathUtilities(std::string url);

private:
    ofstream ocachefile;
    ifstream icachefile;

    std::string urlhash;
};

